package com.example.justbuy.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MySqlMD5Until {
	public static String javamd5jm(String str){
		String md5_32="";
		try {
	        byte[] c = str.getBytes();
	        //????md5?????????
	        MessageDigest md = MessageDigest.getInstance("MD5");
	        md.update(str.getBytes());
	        byte b[] = md.digest();
	        int i;
	        StringBuffer buf = new StringBuffer("");
	        for (int j = 0; j < b.length; j++) {
	            i = b[j];
	            if (i < 0)
	                 i += 256;
	             if (i < 16)
	                 buf.append("0");
	             buf.append(Integer.toHexString(i));
	         }


	         md5_32 = buf.toString();		//32?????
//	         String md5_16 = buf.toString().substring(8, 24);	//16?????
	         
	         System.out.println("MD5(" + str + ",32) = " + md5_32);
//	         System.out.println("MD5(" + str + ",16) = " + md5_16);
	     } catch (NoSuchAlgorithmException e) {
	         System.out.println(e);
	     }
		return md5_32;
	}
}
